//
//  PS_PhotoView.m
//  PolicySystem
//
//  Created by 薛子 on 2018/12/2.
//  Copyright © 2018年 xuezi. All rights reserved.
//

#import "PS_PhotoView.h"
#define MENUNUM  3

@interface PS_PhotoView ()<UIGestureRecognizerDelegate>
@end
@implementation PS_PhotoView
-(instancetype)initWithFrame:(CGRect)frame{
    
    
    if (self = [super initWithFrame:frame]) {
        
        _picImage= [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        _picImage.clipsToBounds = YES;
        _picImage.layer.cornerRadius = 5;
        _picImage.backgroundColor = [UIColor clearColor];
        _picImage.userInteractionEnabled = YES;
        _picImage.contentMode = UIViewContentModeScaleAspectFill;
        [self addSubview:_picImage];
        
        _tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(bigImageAction:)];
        [_picImage addGestureRecognizer:_tap];
        
        _deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _deleteBtn.frame = CGRectMake(frame.size.width-10,-10, 20, 20);
        [_deleteBtn setImage:[UIImage imageNamed:@"delete"] forState:UIControlStateNormal];
        [_deleteBtn addTarget:self action:@selector(deletePhotoAction:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_deleteBtn];
        
        }
    
    
    return self;
}

- (void)bigImageAction:(UIGestureRecognizer *)sender{
    
    if ([self.delegate respondsToSelector:@selector(photoViewSelectedIndex:)]) {
        
        [_delegate photoViewSelectedIndex:sender.view.tag];
    }
   
}
- (void)deletePhotoAction:(UIButton *)sender{
    
    if ([self.deletePhotoDelegate respondsToSelector:@selector(deletePhoto:)]) {
        
        [_deletePhotoDelegate deletePhoto:sender.tag];
    }
    
    
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
